class RolesController < ApplicationController
   before_action :set_menu

  def index
    @submenu = :role_list
    @title = '角色管理'
    @roles = Role.all
  end

  def new
    @role = Role.new
  end

  def create
    @role = Role.new post_params
    if @role.save
      redirect_to roles_path
    else
      render :action => 'new'
    end
  end

  def edit
    @role = Role.find params[:id]
  end

  def update
    @role = Role.find params[:id]
    if @role.update_attributes post_params
      redirect_to roles_path
    else
      render :action => 'edit'
    end
  end

  def destroy
    @role = Role.find params[:id]
    @role.destroy
    redirect_to roles_path
  end


  def post_params
    params.require(:role).permit(:name, { :abilities => [] } )
  end

  private
  def set_menu
    @mainmenu = :people
  end
end
